#ifndef KD_TREE_H
#define KD_TREE_H

#include <vector>

#include "src/scene/photon.h"
#include "src/scene/nearestPhoton.h"

#define X 0
#define Y 1
#define Z 2

//é uma kdtree heap
class KdTree
{
    public:
        KdTree();
        ~KdTree();

        void print(unsigned int, std::string);

        void createHeap();
        void drawPhotons() const;

        void locateNearestPhotons(const unsigned int &, const double &, const double &, const Vector3D &, std::vector<NearestPhoton> *) const;

        void addPhoton(Photon *_p) {photons.push_back(_p);};
        unsigned int getPhotonsSize() const {return photons.size();};
        Photon *getPhoton(unsigned int _i) const {return photons[_i];};

    private:
        std::vector<Photon *> photons;

        void balance(std::vector<Photon *> *, int, int, unsigned int);
        unsigned short findAxis(std::vector<Photon *> *, int, int);

        void quickSort(std::vector<Photon *> *, int, int, unsigned short);
        int partition(std::vector<Photon *> *, int, int, unsigned short);

        void swap(std::vector<Photon *> *, unsigned int, unsigned int);
};

#endif
